package <%= config.basePackage %>service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
<% if(config.page === 'pageHelper') {%>
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
<%}%>
<% if(config.page === 'mybatisPage') {%>
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
<%}%>
import <%= config.basePackage %>common.Result;
import <%= config.basePackage %>entity.<%= table.className %>;
import <%= config.basePackage %>service.<%= table.className %>Service;
import <%= config.basePackage %>mapper.<%= table.className %>Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;


/**
* @author <%= config.author %>
* @date  <%= config.date %>
* @description <%= table.tableName %> <%= table.tableComment %>实现类
* Generated By: uToolsPlugin SqlConvert
* Lesscoding Generate Service
* @version: 0.0.5
* Link to: <a href="https://lesscoding.net">https://lesscoding.net</a>
* mail to:2496290990@qq.com
*/
@Service
@Slf4j
public class <%= table.className %>ServiceImpl extends ServiceImpl<<%= table.className %>Mapper, <%= table.className %>> implements <%= table.className %>Service {

    @Autowired
    private <%= table.className %>Mapper <%= table.firstLowerClassName %>Mapper;

    <% if(config.page === 'pageHelper') {%>
    /**
    * 根据条件分页查询表格结果
    * @return Result
    */
    @Override
    public PageInfo<<%= table.className %>> getPageByLike(<%= table.className %> <%= table.firstLowerClassName %>){
        PageHelper.startPage(<%= table.firstLowerClassName %>.getCurrentPage(),<%= table.firstLowerClassName %>.getPageSize());
        List<<%= table.className %>> pageByLike = <%= table.firstLowerClassName %>Mapper.getPageByLike(<%= table.firstLowerClassName %>);
        return new PageInfo<<%= table.className %>>(pageByLike)
    }
    <%}%>
    <% if(config.page === 'mybatisPage') {%>
    /**
    * 根据条件分页查询表格结果
    * @return Result
    */
    @Override
    public Page<<%= table.className %>> getPageByLike(<%= table.className %> <%= table.firstLowerClassName %>){
        PageDTO page = <%= table.firstLowerClassName %>.getPage();
        List<<%= table.className %>> list = <%= table.firstLowerClassName %>Mapper.getPageByLike(page, <%= table.firstLowerClassName %>);
        page.setRecords(list);
        return page;
    }
    <%}%>
    <% if(config.exportFlag) {%>
        /**
        * 下载导入模板
        * @param response
        */
        @Override
        public void downloadTemplate(HttpServletResponse response){
            throw new RuntimeException("功能暂未实现");
        }

        /**
        * 从excel批量导入数据
        * @return
        */
        @Override
        public Integer import4Excel(MultipartFile file){
            throw new RuntimeException("功能暂未实现");
        }

        /**
        * 导出为excel
        * @param response
        */
        @Override
        public void export2Excel(<%= table.className %> <%= table.firstLowerClassName %>,HttpServletResponse response){
            throw new RuntimeException("功能暂未实现");
        }
    <%}%>

    /**
    * 编辑
    * @return
    */
    @Override
    public Integer edit<%= table.className %>(<%= table.className %> <%= table.firstLowerClassName %>){
        int effect = <%= table.firstLowerClassName %>.get<%=primaryKey.camelCaseField%>() == null ?
            <%= table.firstLowerClassName %>Mapper.insert(<%= table.firstLowerClassName %>) :
            <%= table.firstLowerClassName %>Mapper.updateById(<%= table.firstLowerClassName %>);
        return effect;
    }
}
